import request from '@/utils/request';
import { RcFile } from 'antd/lib/upload';

export async function uploadPdf(file: RcFile) {
  const formData = new FormData();
  formData.append('file', file, file.name);
  return request('/tsapi/file/upload', {
    method: 'POST',
    body: formData,
  });
}

export async function compareUpload(oFile: RcFile, mFile: RcFile) {
  const formData = new FormData();
  formData.append('oFile', oFile, oFile.name);
  formData.append('mFile', mFile, mFile.name);
  return request('/tsapi/file/upload', {
    method: 'POST',
    body: formData,
  });
}

export async function invocations(params: { m: string; o: string }) {
  return request('/t3api/invocations', {
    method: 'POST',
    timeout: 0,
    headers: {
      'Content-Type': 'application/json; format=pandas-split',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      columns: ['pdf_m', 'pdf_o'],
      index: [0],
      data: [[params.m, params.o]],
    }).replaceAll('/', '\\/'),
  });
}
